/*
 * WirelessPowerReceiver.c
 *
 * Created: 04.06.2012 17:54:03
 *  Author: denis
 */ 


#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <string.h>

#include <avr/pgmspace.h>

#define F_CPU 8000000UL	/* CPU clock in Hertz */
#include <util/delay.h>

#define cbi(reg,bit)	reg &= ~(_BV(bit))
#define sbi(reg,bit)	reg |= (_BV(bit))

#define MODE_ON	0
#define MODE_PING	1

volatile uint8_t flow;
volatile uint8_t flow_flag;
volatile uint8_t mode = MODE_ON;

ISR(TIMER2_OVF_vect)
{
	cbi(PORTB,1);
/*	switch(mode)
	{
		case MODE_ON:
		
		cbi(PORTB,1);
		if (flow_flag == 1) //UP
		{
			if(flow<250) flow +=2;
			else flow_flag = 0;
		}
		else //down
		{
			if(flow>5) flow -=2;
			else flow_flag = 1;
		}
		OCR2 = flow;
		break;
		
		case MODE_PING:

		if (flow_flag == 1) //UP
		{
			if(flow<20) flow++;
			else flow_flag = 0;
			cbi(PORTB,1);
		}
		else //down
		{
			if(flow>5) flow--;
			else flow_flag = 1;
			sbi(PORTB,1);
		}
		OCR2 = 200;
		break;
	}*/
}

ISR(TIMER2_COMP_vect)
{
	sbi(PORTB,1);
}


int main(void)
{
	DDRB = 0xFF;
	
	//LED BLINK INIT
	TCCR2 = _BV(CS22)|_BV(CS21);
	TIMSK = _BV(OCIE2)|_BV(TOIE2);
	OCR2 = 100;
	//mode = MODE_PING;
sei(); 
	
    while(1)
    {
        //TODO:: Please write your application code 
		_delay_ms(1000);
		sbi(PORTB,0);
		_delay_ms(10);
		cbi(PORTB,0);
    }
}